package com.xueshishasha.oa.business.Command
{
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.xueshishasha.oa.VO.Employee;
	import com.xueshishasha.oa.business.Delegate.EmployeeDelegate;
	import com.xueshishasha.oa.business.Event.EmployeeLoginEvent;
	import com.xueshishasha.oa.model.OAModelLocator;
	
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class EmployeeLoginCommand implements Command,IResponder
	{
		private var _model :OAModelLocator = OAModelLocator.getInstance();

		public function EmployeeLoginCommand()
		{
		}
		
		public function execute(event:CairngormEvent):void
		{
			var e : EmployeeLoginEvent = EmployeeLoginEvent(event); 			
			var employee :Employee = e.employee;

			var emloyeeDelegate:EmployeeDelegate = new EmployeeDelegate(this);

			emloyeeDelegate.EmployeeLogin(employee);				
		}
		public function result(data:Object):void{
			var event:ResultEvent = data as ResultEvent;
			_model.employee = event.result as Employee;
			_model.eIsLogin = "你好，"+_model.employee.name+"！ID="+_model.employee.id+", 你的身份是"+_model.employee.role.name+"";
		}
		
		public function fault(data:Object):void{
			var event:FaultEvent = data as FaultEvent;
			_model.eIsLogin = "登陆失败";
		}

	}
}